﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core;

namespace WatiN.Sharepoint.WebControls
{
    public class Navigation : Control<Div>
    {
        public override Core.Constraints.Constraint ElementConstraint
        {
            get
            {
                return Find.ByClass("menu vertical menu-vertical") || Find.ByClass("menu horizontal menu-horizontal");
            }
        }

        public List<MenuItem> MenuItems
        {
            get
            {
                var items = new List<MenuItem>();

                var menuLinks = this.Element.Links;

                foreach (Link menuLink in menuLinks)
                {
                    items.Add(new MenuItem(menuLink));
                }

                return items;
            }
        }

        public class MenuItem
        {
            private Link _menuLink = null;

            public MenuItem(Link menuLink)
            {
                _menuLink = menuLink;
            }

            public string Title
            {
                get
                {
                    return _menuLink.Span(Find.ByClass("menu-item-text")).Text;
                }
            }

            public void Click()
            {
                _menuLink.Click();
            }
        }
    }
}
